/*
 * --------------------------------------------------------------
 * Copyright ©  2015 Hangzhou DtDream Technologies Co.,Ltd.
 * --------------------------------------------------------------
 *      Product: 协同数治
 *  Module Name: design
 * Date Created: 2023/2/23
 *  Description: TODO
 * --------------------------------------------------------------
 * Modification History
 * DATE            NAME            Description
 * --------------------------------------------------------------
 * 2023/2/23       yewj            TODO
 * --------------------------------------------------------------
 */

package com.dtdream.pattern.command;

/**
 * TODO
 *
 * @Author: yewj
 **/
public class RemoteController {

    // 开 按钮的命令数组
    private Command[] onCommand;
    private Command[] offCommand;

    // 执行撤销的命令
    private Command undoCommand;

    // 构造器

    public RemoteController() {

        onCommand = new Command[5];
        offCommand = new Command[5];

        for (int i = 0; i < 5; i++) {
            onCommand[i] = new NoCommand();
            offCommand[i] = new NoCommand();
        }

    }

    public void setCommand(int no, Command onCommand, Command offCommand) {
        this.onCommand[no] = onCommand;
        this.offCommand[no] = offCommand;
    }

    public void onButtonWasPushed(int no) {
        onCommand[no].execute();
        undoCommand = onCommand[no];
    }

    public void offButtonWasPushed(int no) {
        offCommand[no].execute();
        undoCommand = offCommand[no];
    }

    public void undoButtonWasPushed() {
        undoCommand.undo();
    }
}
